package com.pet.platform.mapper;

import com.pet.platform.entity.Order;
import com.pet.platform.entity.OrderItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Mapper
public interface OrderMapper {
    void insert(Order order);
    
    void insertOrderItem(OrderItem orderItem);
    
    Optional<Order> findById(@Param("id") Long id);
    
    List<Order> findList(Map<String, Object> params);
    
    Long count(Map<String, Object> params);
    
    void update(Order order);
    
    void delete(@Param("id") Long id);
    
    void updateStatus(@Param("id") Long id, 
                     @Param("status") String status,
                     @Param("updatedTime") LocalDateTime updatedTime);
    
    List<Order> findByUserId(@Param("userId") Long userId, 
                            @Param("offset") Integer offset, 
                            @Param("limit") Integer limit);
    
    List<Order> findByUserIdAndStatus(@Param("userId") Long userId, 
                                    @Param("status") String status, 
                                    @Param("offset") Integer offset, 
                                    @Param("limit") Integer limit);
    
    List<Order> findByKeyword(@Param("keyword") String keyword, 
                             @Param("orderNo") String orderNo,
                             @Param("username") String username,
                             @Param("status") String status,
                             @Param("startDate") LocalDateTime startDate,
                             @Param("endDate") LocalDateTime endDate,
                             @Param("offset") Integer offset, 
                             @Param("limit") Integer limit);
    
    Long countByUserId(@Param("userId") Long userId);
    
    Long countByUserIdAndStatus(@Param("userId") Long userId, 
                               @Param("status") String status);
    
    Long countByKeyword(@Param("keyword") String keyword,
                         @Param("orderNo") String orderNo,
                         @Param("username") String username,
                         @Param("status") String status,
                         @Param("startDate") LocalDateTime startDate,
                         @Param("endDate") LocalDateTime endDate);
    
    void deleteById(Long id);
    
    void deleteOrderItems(Long orderId);
    
    List<OrderItem> findOrderItems(Long orderId);
    
    boolean existsByOrderNo(String orderNo);

    BigDecimal getTotalSales();

    List<Order> findLatestOrders(@Param("limit") Integer limit);

    /**
     * 获取订单总数
     */
    Long count();
} 